#include <iostream>
using namespace std;
int maxA,maxB;

int getSum(int *arr,int i,int j){
    int sum = 0;
    for(;i <= j;i++)
        sum+=arr[i];
    return sum;
}

int getMax(int *arr,int len){
    int max = arr[0];
    for(int i = 0;i < len;i++){
        for(int j = i;j < len;j++){
            int sum = getSum(arr,i,j);
            if(sum >= max){
                max = sum;
                maxA = i;
                maxB = j;
            }
        }
    }
    return max;
}

int main(){
    int arr[] = {1,-1,2,2,3,-3,4,-4};
    int max = getMax(arr,sizeof(arr)/sizeof(int));
    cout << max << endl;
    for(int i = maxA;i <= maxB;i++)
        cout << arr[i] << " ";
    cout << endl;
    return 1;
}